/*
 * Flashlib - QB9 common Flash library
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.qb9.flashlib.prototyping.shapes
{
	import com.qb9.flashlib.geom.Anchor;
	import com.qb9.flashlib.interfaces.IDisposable;
	import com.qb9.flashlib.interfaces.IMoveable;
	
	import flash.display.Graphics;
	import flash.display.Sprite;

	public class BasicShape extends Sprite implements IMoveable, IDisposable
	{
		// Can be replaced
		public static var defaultAnchor:Anchor = Anchor.topLeft;
		
		protected var config:BasicShapeConfig;
		protected var anchor:Anchor;
		protected var g:Graphics;
		
		public function BasicShape(config:Object=null, anchor:Anchor=null)
		{
			if (config === null)
				config = -1;
			if (config is Number)
				config = new BasicShapeConfig(int(config))
			
			this.config = config as BasicShapeConfig;
			this.anchor = anchor || defaultAnchor; 
			
			g = graphics
			paint(config.color);
		}
		
		public function paint(color:int) : void
		{
			g.clear();

			if (color !== -1)
				g.beginFill(color, config.alpha);
			else
				g.beginFill(0, 0);
			
			if (config.borderWidth)
				g.lineStyle(config.borderWidth, config.borderColor, config.borderAlpha);

			draw();
			g.endFill();
		}
		
		protected function draw() : void
		{
			// OVERRIDEME
		}
		
		public function dispose():void
		{
			g = null;
			config = null;
			anchor = null;
		}
		
	}
}